#
# Copyright (C) 2012-2018 Xilinx, Inc.
#
# This file is part of the port for FreeRTOS made by Xilinx to allow FreeRTOS
# to operate with Xilinx Zynq devices.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software. If you wish to use our Amazon
# FreeRTOS name, please do so in a fair use way that does not cause confusion.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# http://www.FreeRTOS.org
# http://aws.amazon.com/freertos
#
# 1 tab == 4 spaces!
#

#
# Processor architecture
# microblaze
#
ARCH = microblaze

SYSTEMDIR = ../../..

TOPDIR = .

ARCH_PREFIX = mb

#
# gnu tools for Makefile
#
CC = $(ARCH_PREFIX)-gcc
AS = $(ARCH_PREFIX)-as
AR = $(ARCH_PREFIX)-ar
CP = cp

#
# Compiler, linker and other options.
#
CFLAGS = ${COMPILER_FLAGS} ${EXTRA_COMPILER_FLAGS}

#
# System project directories.
#
LIBDIR = $(SYSTEMDIR)/lib
INCLUDEDIR = $(SYSTEMDIR)/include

# Kernel library.
LIBFREERTOS = ${LIBDIR}/libfreertos.a
LIBXIL = ${LIBDIR}/libxil.a

INCLUDEFILES =	${TOPDIR}/*.h

INCLUDES = -I$(INCLUDEDIR) \
	-I${TOPDIR}

KERNEL_AR_OBJS = *.c *.S

OUTS = *.o

OBJECTS =	$(addsuffix .o, $(basename $(wildcard *.c)))

STANDALONE_VERSION = $(wildcard ../../standalone_*)

libs:	$(KERNEL_AR_OBJS)
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src libs
	@echo "Compiling FreeRTOS"
	@$(COMPILER) $(COMPILER_FLAGS) $(EXTRA_COMPILER_FLAGS) $(INCLUDES) $^
	@$(ARCHIVER) -r ${LIBFREERTOS} ${OUTS}
	@$(ARCHIVER) -d ${LIBXIL} asm_vectors.o
	@$(ARCHIVER) -s ${LIBXIL}

	make clean




include_standalone:
	@echo "includes"
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src include
	$(CP) -rf $(INCLUDEFILES) $(INCLUDEDIR)


.PHONY: include
include:
	@echo "include"
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src include
	${CP} ${INCLUDEFILES} ${INCLUDEDIR}

clean:
	rm -rf ${OBJECTS}





#PROCESSOR = microblaze_0
#LIBRARIES = ${PROCESSOR}/lib/libxil.a
#BSP_MAKEFILES := $(wildcard $(PROCESSOR)/libsrc/*/src/Makefile)
#SUBDIRS := $(patsubst %/Makefile, %, $(BSP_MAKEFILES))
#
#ifneq (,$(findstring win,$(RDI_PLATFORM)))
# SHELL = CMD
#endif
#
#all: libs
#	@echo 'Finished building libraries'
#
#include: $(addsuffix /make.include,$(SUBDIRS))
#
#libs: $(addsuffix /make.libs,$(SUBDIRS))
#
#$(PROCESSOR)/lib/libxil.a: $(PROCESSOR)/lib/libxil_init.a
#	cp -f $< $@
#
#%/make.include: $(if $(wildcard $(PROCESSOR)/lib/libxil_init.a),$(PROCESSOR)/lib/libxil.a,)
#	@echo "Running Make include in $(subst /make.include,,$@)"
#	$(MAKE) -C $(subst /make.include,,$@) -s include  "SHELL=$(SHELL)" "COMPILER=mb-gcc" "ARCHIVER=mb-ar" "COMPILER_FLAGS= -O2 -c -mcpu=v9.4 -mhard-float -mlittle-endian #-mno-xl-soft-div -mno-xl-soft-mul -mxl-barrel-shift -mxl-float-convert -mxl-float-sqrt -mxl-multiply-high -mxl-pattern-compare" "EXTRA_COMPILER_FLAGS=-g -ffunction-sections #-fdata-sections"
#
#%/make.libs: include
#	@echo "Running Make libs in $(subst /make.libs,,$@)"
#	$(MAKE) -C $(subst /make.libs,,$@) -s libs  "SHELL=$(SHELL)" "COMPILER=mb-gcc" "ARCHIVER=mb-ar" "COMPILER_FLAGS= -O2 -c -mcpu=v9.4 -mhard-float -mlittle-endian #-mno-xl-soft-div -mno-xl-soft-mul -mxl-barrel-shift -mxl-float-convert -mxl-float-sqrt -mxl-multiply-high -mxl-pattern-compare" "EXTRA_COMPILER_FLAGS=-g -ffunction-sections #-fdata-sections"
#
#clean:
#	rm -f ${PROCESSOR}/lib/libxil.a
